package View;

import Controller.POSSystem;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MainFrame extends JFrame {

    private JButton button = new JButton("开始一次新销售活动");
    private static MainFrame instance;

    private MainFrame() {

        setTitle("主窗口");
        setSize(300, 450);

        button.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                makeNewSale();
            }
        });

        Container pane = getContentPane();
        pane.setLayout(new FlowLayout(FlowLayout.CENTER,20,180));
        pane.add(button);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private void makeNewSale() {
        POSSystem.getInstance().makeNewSale();
        conceal();
    }

    public static MainFrame getInstance() {
        if (instance == null) {
            instance = new MainFrame();
        }
        return instance;
    }

    public void display() {
        if (!isVisible())
            setVisible(true);
    }

    public void conceal() {
        if (isVisible())
            setVisible(false);
    }
}
